package cn.mofuxiong.interceptor;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;

import cn.mofuxiong.Model.login_register;
import cn.mofuxiong.action.Login_Register_Action;

import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;

public class MyInterceptor extends AbstractInterceptor
{

	@Override
	public String intercept(ActionInvocation arg0) throws Exception 
	{
		HttpServletRequest req;
		String user;
		ActionSupport action;
		
		req = ServletActionContext.getRequest();
		user = (String) req.getSession().getAttribute("UserId");
		action=(ActionSupport)arg0.getAction();
		
		if(user!=null)
		{
			return arg0.invoke();
		}
		else if(user==null)
		{
			if(action!=null&&action instanceof Login_Register_Action)
			{
				return arg0.invoke();
			}
			else 
			{
				return "no_login";
			}
		}
		return null;
	}

}
